package com.qdu.mr;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class CountRunner {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        // 创建一个配置对象，存放Hadoop的job运行需要的所有配置信息
        Configuration conf = new Configuration();
        // 获取Job的实例
        Job job = Job.getInstance(conf);
        // 设置Job的jar的类
        job.setJarByClass(CountRunner.class);

        // 设置Mapper的类、Mapper输出的K-V的类型
        job.setMapperClass(CountMapper.class);
        job.setMapOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);

        // 设置Reducer的类、Job的输出的K-V的类型
        job.setReducerClass(CountReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);

        // 设置输入文件夹
        FileInputFormat.addInputPath(job,new Path("input"));

        // 设置输出文件夹
        FileOutputFormat.setOutputPath(job,new Path("output/wordcount"));
        // 启动job
        job.waitForCompletion(true);
    }
}
